package com.gxa.web_admin.controller.csr;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gxa.common.base.RespResult;
import com.gxa.common.constants.Constants;

import com.gxa.modules.core.EntityExcelExport;
import com.gxa.modules.dto.cw.*;
import com.gxa.modules.entity.CrmCapitalAccount;
import com.gxa.modules.entity.CrmFinancial;
import com.gxa.modules.entity.CrmMoneyType;
import com.gxa.modules.service.CrmFinancialService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/CW")
@Slf4j
@Api(value = "财务管理",tags = "财务管理接口API")
public class FinanceController {
    @Autowired
    private CrmFinancialService crmFinancialService;
    @Autowired
    private EntityExcelExport entityExcelExport;
    @RequestMapping("/selectAll")
    @ApiOperation(value = "查看所有财务管理",notes = "接收页数和条数",httpMethod = "POST", response = RespResult.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页数",paramType = "query",dataType = "Integer",required = true),
            @ApiImplicitParam(name = "limit",value = "条数",paramType = "query",dataType = "Integer",required = true)
    })
    public RespResult selectAll(Integer page, Integer limit){
        Page<CrmFinancial> page1 = new Page<>(page, limit);
        QueryWrapper<CrmFinancial> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("del_status", Constants.DEL_STATUS);
        Page<CrmFinancial> page2 = crmFinancialService.page(page1, queryWrapper);
        System.out.println(page2.getRecords());
        RespResult<List<CrmFinancial>> success = RespResult.success(page2.getRecords());
        return success;
    }
    @RequestMapping("/selectAllByname")
    @ApiOperation(value = "所有搜索查询",notes = "接收页数和条数",httpMethod = "POST", response = RespResult.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页数",paramType = "query",dataType = "Integer",required = true),
            @ApiImplicitParam(name = "limit",value = "条数",paramType = "query",dataType = "Integer",required = true),
            @ApiImplicitParam(name = "name",value = "客户名称",paramType = "query",dataType = "String",required = true)
    })
    public RespResult selectAllByname(Integer page,Integer limit,String name){
        Page<CrmFinancial> page1 = new Page<>(page, limit);
        QueryWrapper<CrmFinancial> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("del_status", Constants.DEL_STATUS)
                .like("customer_name",name);
        Page<CrmFinancial> page2 = crmFinancialService.page(page1, queryWrapper);
        RespResult<List<CrmFinancial>> success = RespResult.success(page2.getRecords());
        return success;
    }
    @RequestMapping("/selectAllBymany")
    @ApiOperation(value = "所有高级搜索查询",notes = "接收页数和条数",httpMethod = "POST", response = RespResult.class)
    public RespResult selectAllBymany(@RequestBody @ApiParam(name = "finance1",value = "高级搜索条件",required = true) Finance1 finance1){
        Page<CrmFinancial> page = new Page<>(finance1.getPage(), finance1.getLimit());
        QueryWrapper<CrmFinancial> queryWrapper = new QueryWrapper<>();
        if (finance1.getCustomerName()!=null){
            queryWrapper.eq("customer_name",finance1.getCustomerName());
        }
        if (finance1.getContacts()!=null){
            queryWrapper.eq("contacts",finance1.getContacts());
        }
        if (finance1.getAmountType()!=null){
            queryWrapper.eq("amount_type",finance1.getAmountType());
        }
        if (finance1.getMoneyType()!=null){
            queryWrapper.eq("money_type",finance1.getMoneyType());
        }
        if (finance1.getMoney()!=null){
            queryWrapper.eq("money",finance1.getMoney());
        }
        if (finance1.getRemarks()!=null){
            queryWrapper.eq("remarks",finance1.getRemarks());
        }
        if (finance1.getSpendTime1()!=null&&finance1.getSpendTime2()!=null){
            queryWrapper.between("spend_time",finance1.getSpendTime1(),finance1.getSpendTime2());
        }
        if (finance1.getCapitalAccount()!=null){
            queryWrapper.eq("capital_account",finance1.getCapitalAccount());
        }
        if (finance1.getProcessor()!=null){
            queryWrapper.eq("processor",finance1.getProcessor());
        }
        if (finance1.getSalesman()!=null){
            queryWrapper.eq("salesman",finance1.getSalesman());
        }
        if (finance1.getStatus()!=null){
            queryWrapper.eq("status",finance1.getStatus());
        }
        queryWrapper.eq("del_status",Constants.DEL_STATUS);

        Page<CrmFinancial> page1 = crmFinancialService.page(page, queryWrapper);
        RespResult<List<CrmFinancial>> success = RespResult.success(page1.getRecords());
        return success;
    }
    @RequestMapping("/selectAllBymanyfile")
    @ApiOperation(value = "所有高级搜索导出",notes = "接收页数和条数",httpMethod = "POST", response = RespResult.class)
    public void selectAllBymanyfile(@RequestBody @ApiParam(name = "finance2",value = "高级搜索条件",required = true) Finance2 finance2, HttpServletResponse response){
        entityExcelExport.exportWithSmallData(response, "雇员列表", finance2);
    }
    @RequestMapping("/findFiles")
    @ApiOperation(value = "查询附件",notes = "接收页数和条数",httpMethod = "POST", response = RespResult.class)
    @ApiImplicitParam(name = "id",value = "财务id",paramType = "query",dataType = "Integer",required = true)
    public RespResult findFiles(Integer id){

        CrmFinancial crmFinancial = new CrmFinancial();
        crmFinancial.setCustomerName("杜鑫东");
        crmFinancial.setRelatedContract("-");
        crmFinancial.setContacts("杜鑫东他爸");
        crmFinancial.setAmountType("支出");
        crmFinancial.setMoneyType("合同款");
        crmFinancial.setMoney("5000");
        crmFinancial.setRemarks("无");
        crmFinancial.setSpendTime(new Date());
        crmFinancial.setCapitalAccount("微信");
        crmFinancial.setProcessor("张三");
        crmFinancial.setSalesman("张三");
        crmFinancial.setLoadTime(new Date());
        crmFinancial.setFile("aaa.jpg");
        crmFinancial.setStatus(0);
        crmFinancial.setDelStatus(0);
        RespResult<CrmFinancial> success = RespResult.success(crmFinancial);
        return success;
    }
    @RequestMapping("/delfile")
    @ApiOperation(value = "删除附件",notes = "接收页数和条数",httpMethod = "POST", response = RespResult.class)
    @ApiImplicitParam(name = "id",value = "附件id",paramType = "query",dataType = "Integer",required = true)
    public RespResult delfile(Integer id){

        CrmFinancial crmFinancial = new CrmFinancial();
        crmFinancial.setCustomerName("杜鑫东");
        crmFinancial.setRelatedContract("-");
        crmFinancial.setContacts("杜鑫东他爸");
        crmFinancial.setAmountType("支出");
        crmFinancial.setMoneyType("合同款");
        crmFinancial.setMoney("5000");
        crmFinancial.setRemarks("无");
        crmFinancial.setSpendTime(new Date());
        crmFinancial.setCapitalAccount("微信");
        crmFinancial.setProcessor("张三");
        crmFinancial.setSalesman("张三");
        crmFinancial.setLoadTime(new Date());
        crmFinancial.setFile("aaa.jpg");
        crmFinancial.setStatus(0);
        crmFinancial.setDelStatus(0);
        RespResult<CrmFinancial> success = RespResult.success(crmFinancial);
        return success;
    }
    @RequestMapping("/seleclByid")
    @ApiOperation(value = "信息回显",notes = "接收页数和条数",httpMethod = "POST", response = RespResult.class)
    @ApiImplicitParam(name = "id",value = "附件id",paramType = "query",dataType = "Integer",required = true)
    public RespResult seleclByid(Integer id){

        CrmFinancial crmFinancial = new CrmFinancial();
        crmFinancial.setCustomerName("杜鑫东");
        crmFinancial.setRelatedContract("-");
        crmFinancial.setContacts("杜鑫东他爸");
        crmFinancial.setAmountType("支出");
        crmFinancial.setMoneyType("合同款");
        crmFinancial.setMoney("5000");
        crmFinancial.setRemarks("无");
        crmFinancial.setSpendTime(new Date());
        crmFinancial.setCapitalAccount("微信");
        crmFinancial.setProcessor("张三");
        crmFinancial.setSalesman("张三");
        crmFinancial.setLoadTime(new Date());
        crmFinancial.setFile("aaa.jpg");
        crmFinancial.setStatus(0);
        crmFinancial.setDelStatus(0);
        RespResult<CrmFinancial> success = RespResult.success(crmFinancial);
        return success;
    }
    @RequestMapping("/findtype")
    @ApiOperation(value = "查询收支类别",notes = "接收页数和条数",httpMethod = "POST", response = RespResult.class)
    public RespResult<CrmMoneyType> findtype(){

        CrmMoneyType crmMoneyType = new CrmMoneyType();
        crmMoneyType.setId(1);
        crmMoneyType.setMoneyType("合同款");
        RespResult<CrmMoneyType> success = RespResult.success(crmMoneyType);
        return success;
    }
    @RequestMapping("/addtype")
    @ApiOperation(value = "查询收支类别",notes = "接收页数和条数",httpMethod = "POST", response = RespResult.class)
    @ApiImplicitParam(name = "name",value = "类别名",paramType = "query",dataType = "String",required = true)
    public RespResult addtype(String name){
        RespResult<Void> success = RespResult.success();
        return success;
    }
    @RequestMapping("/deletetype")
    @ApiOperation(value = "查询收支类别",notes = "接收页数和条数",httpMethod = "POST", response = RespResult.class)
    @ApiImplicitParam(name = "id",value = "类别id",paramType = "query",dataType = "Integer",required = true)
    public RespResult deletetype(Integer id ){
        RespResult<Void> success = RespResult.success();
        return success;
    }
    @RequestMapping("/findaccount")
    @ApiOperation(value = "查询资金账户",notes = "接收页数和条数",httpMethod = "POST", response = RespResult.class)
    public RespResult findaccount(){

        CrmCapitalAccount crmCapitalAccount = new CrmCapitalAccount();
        crmCapitalAccount.setId(1);
        crmCapitalAccount.setCapitalAccount("微信");
        RespResult<CrmCapitalAccount> success = RespResult.success(crmCapitalAccount);
        return success;
    }
    @RequestMapping("/addaccount")
    @ApiOperation(value = "新增资金账户",notes = "接收页数和条数",httpMethod = "POST", response = RespResult.class)
    @ApiImplicitParam(name = "moneyAccount",value = "账户名",paramType = "query",dataType = "String",required = true)
    public RespResult addaccount(String moneyAccount){
        RespResult<Void> success = RespResult.success();
        return success;
    }
    @RequestMapping("/delaccount")
    @ApiOperation(value = "删除资金账户",notes = "接收页数和条数",httpMethod = "POST", response = RespResult.class)
    @ApiImplicitParam(name = "id",value = "账户di",paramType = "query",dataType = "Integer",required = true)
    public RespResult delaccount(Integer id){

        RespResult<Void> success = RespResult.success();
        return success;
    }
    @RequestMapping("/update")
    @ApiOperation(value = "财务信息修改",notes = "接收页数和条数",httpMethod = "POST", response = RespResult.class)
    public RespResult update(@RequestBody @ApiParam(name = "finance3",value = "修改数据",required = true) Finance3 finance3){
        RespResult<Void> success = RespResult.success();
        return success;
    }
    @RequestMapping("/delete")
    @ApiOperation(value = "删除财务",notes = "接收页数和条数",httpMethod = "POST", response = RespResult.class)
    @ApiImplicitParam(name = "id",value = "财务id",paramType = "query",dataType = "Integer",required = true)
    public RespResult delete(Integer id){
        System.out.println(id);
        boolean b = crmFinancialService.removeById(id);
        RespResult<Void> success = RespResult.success();
        return success;
    }
    @RequestMapping("/approval")
    @ApiOperation(value = "状态修改",notes = "接收页数和条数",httpMethod = "POST", response = RespResult.class)
    @ApiImplicitParam(name = "status",value = "财务状态",paramType = "query",dataType = "byte",required = true)
    public RespResult approval(byte status){
        RespResult<Void> success = RespResult.success();
        return success;

    }
    @RequestMapping("/selectAllBytime")
    @ApiOperation(value = "按时间查询所有财务",notes = "接收页数和条数",httpMethod = "POST", response = RespResult.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页数",paramType = "query",dataType = "Integer",required = true),
            @ApiImplicitParam(name = "limit",value = "条数",paramType = "query",dataType = "Integer",required = true),
            @ApiImplicitParam(name = "timeNum",value = "时间类别值",paramType = "query",dataType = "Integer",required = true)
    })
    public RespResult selectAllBytime(Integer page,Integer limit,Integer timeNum){

        CrmFinancial crmFinancial = new CrmFinancial();
        crmFinancial.setCustomerName("杜鑫东");
        crmFinancial.setRelatedContract("-");
        crmFinancial.setContacts("杜鑫东他爸");
        crmFinancial.setAmountType("支出");
        crmFinancial.setMoneyType("合同款");
        crmFinancial.setMoney("5000");
        crmFinancial.setRemarks("无");
        crmFinancial.setSpendTime(new Date());
        crmFinancial.setCapitalAccount("微信");
        crmFinancial.setProcessor("张三");
        crmFinancial.setSalesman("张三");
        crmFinancial.setLoadTime(new Date());
        crmFinancial.setFile("aaa.jpg");
        crmFinancial.setStatus(0);
        crmFinancial.setDelStatus(0);
        RespResult<CrmFinancial> success = RespResult.success(crmFinancial);
        return success;
    }

    @RequestMapping("/selectAllBytimeandname")
    @ApiOperation(value = "搜索查询（按时间）",notes = "接收页数和条数",httpMethod = "POST", response = RespResult.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页数",paramType = "query",dataType = "Integer",required = true),
            @ApiImplicitParam(name = "limit",value = "条数",paramType = "query",dataType = "Integer",required = true),
            @ApiImplicitParam(name = "name",value = "客户名称",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "timeNum",value = "客户名称",paramType = "query",dataType = "Integer",required = true)
    })
    public RespResult selectAllBytimeandname(Integer page,Integer limit,String name,Integer timeNum){

        CrmFinancial crmFinancial = new CrmFinancial();
        crmFinancial.setCustomerName("杜鑫东");
        crmFinancial.setRelatedContract("-");
        crmFinancial.setContacts("杜鑫东他爸");
        crmFinancial.setAmountType("支出");
        crmFinancial.setMoneyType("合同款");
        crmFinancial.setMoney("5000");
        crmFinancial.setRemarks("无");
        crmFinancial.setSpendTime(new Date());
        crmFinancial.setCapitalAccount("微信");
        crmFinancial.setProcessor("张三");
        crmFinancial.setSalesman("张三");
        crmFinancial.setLoadTime(new Date());
        crmFinancial.setFile("aaa.jpg");
        crmFinancial.setStatus(0);
        crmFinancial.setDelStatus(0);
        RespResult<CrmFinancial> success = RespResult.success(crmFinancial);
        return success;
    }
    @RequestMapping("/selectAllBytimeandmany")
    @ApiOperation(value = "高级搜索查询（按时间）",notes = "接收页数和条数",httpMethod = "POST", response = RespResult.class)
    public RespResult selectAllBytimeandmany(@RequestBody @ApiParam(name = "finance4",value = "高级搜索条件",required = true) Finance4 finance4){

        CrmFinancial crmFinancial = new CrmFinancial();
        crmFinancial.setCustomerName("杜鑫东");
        crmFinancial.setRelatedContract("-");
        crmFinancial.setContacts("杜鑫东他爸");
        crmFinancial.setAmountType("支出");
        crmFinancial.setMoneyType("合同款");
        crmFinancial.setMoney("5000");
        crmFinancial.setRemarks("无");
        crmFinancial.setSpendTime(new Date());
        crmFinancial.setCapitalAccount("微信");
        crmFinancial.setProcessor("张三");
        crmFinancial.setSalesman("张三");
        crmFinancial.setLoadTime(new Date());
        crmFinancial.setFile("aaa.jpg");
        crmFinancial.setStatus(0);
        crmFinancial.setDelStatus(0);
        RespResult<CrmFinancial> success = RespResult.success(crmFinancial);
        return success;
    }
    @RequestMapping("/selectAllBymanyfileandtime")
    @ApiOperation(value = "高级搜索文件导出（按时间）",notes = "接收页数和条数",httpMethod = "POST", response = RespResult.class)
    public RespResult selectAllBymanyfileandtime(@RequestBody @ApiParam(name = "finance5",value = "高级搜索条件",required = true) Finance5 finance5){

        CrmFinancial crmFinancial = new CrmFinancial();
        crmFinancial.setCustomerName("杜鑫东");
        crmFinancial.setRelatedContract("-");
        crmFinancial.setContacts("杜鑫东他爸");
        crmFinancial.setAmountType("支出");
        crmFinancial.setMoneyType("合同款");
        crmFinancial.setMoney("5000");
        crmFinancial.setRemarks("无");
        crmFinancial.setSpendTime(new Date());
        crmFinancial.setCapitalAccount("微信");
        crmFinancial.setProcessor("张三");
        crmFinancial.setSalesman("张三");
        crmFinancial.setLoadTime(new Date());
        crmFinancial.setFile("aaa.jpg");
        crmFinancial.setStatus(0);
        crmFinancial.setDelStatus(0);
        RespResult<CrmFinancial> success = RespResult.success(crmFinancial);
        return success;
    }
    @RequestMapping("/findcustomer")
    @ApiOperation(value = "查询所有客户",notes = "接收页数和条数",httpMethod = "POST", response = RespResult.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页数",paramType = "query",dataType = "Integer",required = true),
            @ApiImplicitParam(name = "limit",value = "条数",paramType = "query",dataType = "Integer",required = true)
    })
    public RespResult findcustomer(Integer page,Integer limit){
        RespResult<Void> success = RespResult.success();
        return success;
    }
    @RequestMapping("/findcustomerByname")
    @ApiOperation(value = "查询所有客户",notes = "接收页数和条数",httpMethod = "POST", response = RespResult.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页数",paramType = "query",dataType = "Integer",required = true),
            @ApiImplicitParam(name = "limit",value = "条数",paramType = "query",dataType = "Integer",required = true),
            @ApiImplicitParam(name = "name",value = "客户名称",paramType = "query",dataType = "String",required = true)
    })
    public RespResult findcustomerByname(Integer page,Integer limit,String name){
        RespResult<Void> success = RespResult.success();
        return success;
    }
    @RequestMapping("/addCw")
    @ApiOperation(value = "新增收入",notes = "接收页数和条数",httpMethod = "POST", response = RespResult.class)
    public RespResult addCw(@RequestBody @ApiParam(name = "finance6",value = "高级搜索条件",required = true) Finance6 finance6){
        RespResult<Void> success = RespResult.success();
        return success;
    }
}
